#include "header.h"
#define ARR_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))

void binary_file_cpy(const char* src_file, char* dest_file) {
    FILE* fp_src = fopen(src_file, "rb");
    ERROR_CHECK(fp_src, NULL, "open");

    FILE* fp_dest = fopen(dest_file, "wb");
    if (fp_dest == NULL) {
        fclose(fp_src);
        perror("open");
        exit(-1);
    }


    char buf[8192] = { 0 };	// 中间站的大小是8KB
    // 循环读,循环写
    // 惯用法
    int read_count = 0;		// 一次fread实际读到的字节数量
    
    while ((read_count = fread(buf, 1, 8192, fp_src)) > 0) {		// 读完了fread会返回0
        fwrite(buf, 1, read_count, fp_dest);
    }
    
    fclose(fp_src);
    fclose(fp_dest);

}

int main(int argc, char* argv[]){
	ARGS_CHECK(argc, 3);
    binary_file_cpy(argv[1], argv[2]);

	return 0;
}